<!doctype html>
<html>
<head>
<meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'>
<title>Git实战.md</title><link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext' rel='stylesheet' type='text/css' /><style type='text/css'>html {overflow-x: initial !important;}.CodeMirror { height: auto; }
.CodeMirror-scroll { overflow-y: hidden; overflow-x: auto; }
.CodeMirror-lines { padding: 4px 0px; }
.CodeMirror pre { }
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { background-color: white; }
.CodeMirror-gutters { border-right: 1px solid rgb(221, 221, 221); background-color: rgb(247, 247, 247); white-space: nowrap; }
.CodeMirror-linenumbers { }
.CodeMirror-linenumber { padding: 0px 3px 0px 5px; text-align: right; color: rgb(153, 153, 153); }
.CodeMirror div.CodeMirror-cursor { border-left: 1px solid black; z-index: 3; }
.CodeMirror div.CodeMirror-secondarycursor { border-left: 1px solid silver; }
.CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor { width: auto; border: 0px; background: rgb(119, 238, 119); z-index: 1; }
.CodeMirror div.CodeMirror-cursor.CodeMirror-overwrite { }
.cm-tab { display: inline-block; }
.cm-s-typora-default .cm-header, .cm-s-typora-default .cm-property { color: rgb(217, 79, 138); }
.cm-s-typora-default pre.cm-header1:not(.cm-atom) :not(.cm-overlay) { font-size: 2rem; line-height: 2rem; }
.cm-s-typora-default pre.cm-header2:not(.cm-atom) :not(.cm-overlay) { font-size: 1.4rem; line-height: 1.4rem; }
.cm-s-typora-default .cm-atom, .cm-s-typora-default .cm-number { color: rgb(149, 132, 134); }
.cm-s-typora-default .cm-table-row, .cm-s-typora-default .cm-block-start { font-family: monospace; }
.cm-s-typora-default .cm-comment, .cm-s-typora-default .cm-code { color: rgb(74, 90, 159); font-family: monospace; }
.cm-s-typora-default .cm-tag { color: rgb(169, 68, 66); }
.cm-s-typora-default .cm-string { color: rgb(126, 134, 169); }
.cm-s-typora-default .cm-link { color: rgb(196, 122, 15); text-decoration: underline; }
.cm-s-typora-default .cm-variable-2, .cm-s-typora-default .cm-variable-1 { color: inherit; }
.cm-s-typora-default .cm-overlay { font-size: 1rem; font-family: monospace; }
.CodeMirror.cm-s-typora-default div.CodeMirror-cursor { border-left: 3px solid rgb(228, 98, 154); }
.cm-s-typora-default .CodeMirror-activeline-background { left: -60px; right: -30px; background: rgba(204, 204, 204, 0.2); }
.cm-s-typora-default .CodeMirror-gutters { border-right: none; background-color: inherit; }
.cm-s-typora-default .cm-trailing-space-new-line::after, .cm-startspace::after, .cm-starttab .cm-tab::after { content: "•"; position: absolute; left: 0px; opacity: 0; font-family: LetterGothicStd, monospace; }
.os-windows .cm-startspace::after, .os-windows .cm-starttab .cm-tab::after { left: -0.1em; }
.cm-starttab .cm-tab::after { content: " "; }
.cm-startspace, .cm-tab, .cm-starttab, .cm-trailing-space-a, .cm-trailing-space-b, .cm-trailing-space-new-line { font-family: monospace; position: relative; }
.cm-s-typora-default .cm-trailing-space-new-line::after { content: "↓"; opacity: 0.3; }
.cm-s-inner .cm-keyword { color: rgb(119, 0, 136); }
.cm-s-inner .cm-atom, .cm-s-inner.cm-atom { color: rgb(34, 17, 153); }
.cm-s-inner .cm-number { color: rgb(17, 102, 68); }
.cm-s-inner .cm-def { color: rgb(0, 0, 255); }
.cm-s-inner .cm-variable { color: black; }
.cm-s-inner .cm-variable-2 { color: rgb(0, 85, 170); }
.cm-s-inner .cm-variable-3 { color: rgb(0, 136, 85); }
.cm-s-inner .cm-property { color: black; }
.cm-s-inner .cm-operator { color: rgb(152, 26, 26); }
.cm-s-inner .cm-comment, .cm-s-inner.cm-comment { color: rgb(170, 85, 0); }
.cm-s-inner .cm-string { color: rgb(170, 17, 17); }
.cm-s-inner .cm-string-2 { color: rgb(255, 85, 0); }
.cm-s-inner .cm-meta { color: rgb(85, 85, 85); }
.cm-s-inner .cm-qualifier { color: rgb(85, 85, 85); }
.cm-s-inner .cm-builtin { color: rgb(51, 0, 170); }
.cm-s-inner .cm-bracket { color: rgb(153, 153, 119); }
.cm-s-inner .cm-tag { color: rgb(17, 119, 0); }
.cm-s-inner .cm-attribute { color: rgb(0, 0, 204); }
.cm-s-inner .cm-header, .cm-s-inner.cm-header { color: blue; }
.cm-s-inner .cm-quote, .cm-s-inner.cm-quote { color: rgb(0, 153, 0); }
.cm-s-inner .cm-hr, .cm-s-inner.cm-hr { color: rgb(153, 153, 153); }
.cm-s-inner .cm-link, .cm-s-inner.cm-link { color: rgb(0, 0, 204); }
.cm-negative { color: rgb(221, 68, 68); }
.cm-positive { color: rgb(34, 153, 34); }
.cm-header, .cm-strong { font-weight: bold; }
.cm-del { text-decoration: line-through; }
.cm-em { font-style: italic; }
.cm-link { text-decoration: underline; }
.cm-error { color: rgb(255, 0, 0); }
.cm-invalidchar { color: rgb(255, 0, 0); }
.cm-constant { color: rgb(38, 139, 210); }
.cm-defined { color: rgb(181, 137, 0); }
div.CodeMirror span.CodeMirror-matchingbracket { color: rgb(0, 255, 0); }
div.CodeMirror span.CodeMirror-nonmatchingbracket { color: rgb(255, 34, 34); }
.cm-s-inner .CodeMirror-activeline-background { background: inherit; }
.CodeMirror { position: relative; overflow: hidden; }
.CodeMirror-scroll { margin-bottom: -30px; margin-right: -30px; padding-bottom: 30px; padding-right: 30px; height: 100%; outline: none; position: relative; box-sizing: content-box; }
.CodeMirror-sizer { position: relative; }
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { position: absolute; z-index: 6; display: none; }
.CodeMirror-vscrollbar { right: 0px; top: 0px; overflow-x: hidden; overflow-y: scroll; }
.CodeMirror-hscrollbar { bottom: 0px; left: 0px; overflow-y: hidden; overflow-x: scroll; }
.CodeMirror-scrollbar-filler { right: 0px; bottom: 0px; }
.CodeMirror-gutter-filler { left: 0px; bottom: 0px; }
.CodeMirror-gutters { position: absolute; left: 0px; top: 0px; padding-bottom: 30px; z-index: 3; }
.CodeMirror-gutter { white-space: normal; height: 100%; box-sizing: content-box; padding-bottom: 30px; margin-bottom: -32px; display: inline-block; }
.CodeMirror-gutter-elt { position: absolute; cursor: default; z-index: 4; }
.CodeMirror-lines { cursor: text; }
.CodeMirror pre { border-radius: 0px; border-width: 0px; background: transparent; font-family: inherit; font-size: inherit; margin: 0px; white-space: pre; word-wrap: normal; color: inherit; z-index: 2; position: relative; overflow: visible; }
.CodeMirror-wrap pre { word-wrap: break-word; white-space: pre-wrap; word-break: normal; }
.CodeMirror-code pre { border-right: 30px solid transparent; width: fit-content; }
.CodeMirror-wrap .CodeMirror-code pre { border-right: none; width: auto; }
.CodeMirror-linebackground { position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; z-index: 0; }
.CodeMirror-linewidget { position: relative; z-index: 2; overflow: auto; }
.CodeMirror-widget { }
.CodeMirror-wrap .CodeMirror-scroll { overflow-x: hidden; }
.CodeMirror-measure { position: absolute; width: 100%; height: 0px; overflow: hidden; visibility: hidden; }
.CodeMirror-measure pre { position: static; }
.CodeMirror div.CodeMirror-cursor { position: absolute; visibility: hidden; border-right: none; width: 0px; }
.CodeMirror div.CodeMirror-cursor { visibility: hidden; }
.CodeMirror-focused div.CodeMirror-cursor { visibility: inherit; }
.CodeMirror-selected { background: rgb(217, 217, 217); }
.CodeMirror-focused .CodeMirror-selected { background: rgb(215, 212, 240); }
.cm-searching { background: rgba(255, 255, 0, 0.4); }
.CodeMirror span { }
@media print {
  .CodeMirror div.CodeMirror-cursor { visibility: hidden; }
}
.CodeMirror-lint-markers { width: 16px; }
.CodeMirror-lint-tooltip { background-color: infobackground; border: 1px solid black; border-radius: 4px; color: infotext; font-family: monospace; overflow: hidden; padding: 2px 5px; position: fixed; white-space: pre-wrap; z-index: 10000; max-width: 600px; opacity: 0; transition: opacity 0.4s; font-size: 0.8em; }
.CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning { background-position: left bottom; background-repeat: repeat-x; }
.CodeMirror-lint-mark-error { background-image: url(""); }
.CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning { background-position: center center; background-repeat: no-repeat; cursor: pointer; display: inline-block; height: 16px; width: 16px; vertical-align: middle; position: relative; }
.CodeMirror-lint-message-error, .CodeMirror-lint-message-warning { padding-left: 18px; background-position: left top; background-repeat: no-repeat; }
.CodeMirror-lint-marker-error, .CodeMirror-lint-message-error { background-image: url(""); }
.CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning { background-image: url(""); }
.CodeMirror-lint-marker-multiple { background-image: url(""); background-repeat: no-repeat; background-position: right bottom; width: 100%; height: 100%; }


html { font-size: 14px; background-color: rgb(255, 255, 255); color: rgb(51, 51, 51); }
body { margin: 0px; padding: 0px; height: auto; bottom: 0px; top: 0px; left: 0px; right: 0px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 1rem; line-height: 1.42857; overflow-x: hidden; background: inherit; }
a:active, a:hover { outline: 0px; }
.in-text-selection, ::selection { background: rgb(181, 214, 252); text-shadow: none; }
#write { margin: 0px auto; height: auto; width: inherit; word-break: normal; word-wrap: break-word; position: relative; padding-bottom: 70px; white-space: pre-wrap; overflow-x: visible; }
.for-image #write { padding-left: 8px; padding-right: 8px; }
body.typora-export { padding-left: 30px; padding-right: 30px; }
@media screen and (max-width: 500px) {
  body.typora-export { padding-left: 0px; padding-right: 0px; }
  .CodeMirror-sizer { margin-left: 0px !important; }
  .CodeMirror-gutters { display: none !important; }
}
.typora-export #write { margin: 0px auto; }
#write > p:first-child, #write > ul:first-child, #write > ol:first-child, #write > pre:first-child, #write > blockquote:first-child, #write > div:first-child, #write > table:first-child { margin-top: 30px; }
#write li > table:first-child { margin-top: -20px; }
img { max-width: 100%; vertical-align: middle; }
input, button, select, textarea { color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; }
input[type="checkbox"], input[type="radio"] { line-height: normal; padding: 0px; }
::before, ::after, * { box-sizing: border-box; }
#write p, #write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write div, #write pre { width: inherit; }
#write p, #write h1, #write h2, #write h3, #write h4, #write h5, #write h6 { position: relative; }
h1 { font-size: 2rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.6rem; }
h4 { font-size: 1.4rem; }
h5 { font-size: 1.2rem; }
h6 { font-size: 1rem; }
p { -webkit-margin-before: 1rem; -webkit-margin-after: 1rem; -webkit-margin-start: 0px; -webkit-margin-end: 0px; }
.mathjax-block { margin-top: 0px; margin-bottom: 0px; -webkit-margin-before: 0rem; -webkit-margin-after: 0rem; }
.hidden { display: none; }
.md-blockmeta { color: rgb(204, 204, 204); font-weight: bold; font-style: italic; }
a { cursor: pointer; }
sup.md-footnote { padding: 2px 4px; background-color: rgba(238, 238, 238, 0.701961); color: rgb(85, 85, 85); border-radius: 4px; }
#write input[type="checkbox"] { cursor: pointer; width: inherit; height: inherit; margin: 4px 0px 0px; }
tr { break-inside: avoid; break-after: auto; }
thead { display: table-header-group; }
table { border-collapse: collapse; border-spacing: 0px; width: 100%; overflow: auto; break-inside: auto; text-align: left; }
table.md-table td { min-width: 80px; }
.CodeMirror-gutters { border-right: 0px; background-color: inherit; }
.CodeMirror { text-align: left; }
.CodeMirror-placeholder { opacity: 0.3; }
.CodeMirror pre { padding: 0px 4px; }
.CodeMirror-lines { padding: 0px; }
div.hr:focus { cursor: none; }
pre { white-space: pre-wrap; }
.CodeMirror-gutters { margin-right: 4px; }
.md-fences { font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; overflow: visible; white-space: pre; background: inherit; position: relative !important; }
.md-diagram-panel { width: 100%; margin-top: 10px; text-align: center; padding-top: 0px; padding-bottom: 8px; overflow-x: auto; }
.md-fences .CodeMirror.CodeMirror-wrap { top: -1.6em; margin-bottom: -1.6em; }
.md-fences.mock-cm { white-space: pre-wrap; }
.show-fences-line-number .md-fences { padding-left: 0px; }
.show-fences-line-number .md-fences.mock-cm { padding-left: 40px; }
.footnotes { opacity: 0.8; font-size: 0.9rem; padding-top: 1em; padding-bottom: 1em; }
.footnotes + .footnotes { margin-top: -1em; }
.md-reset { margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: top; background: transparent; text-decoration: none; text-shadow: none; float: none; position: static; width: auto; height: auto; white-space: nowrap; cursor: inherit; -webkit-tap-highlight-color: transparent; line-height: normal; font-weight: normal; text-align: left; box-sizing: content-box; direction: ltr; }
li div { padding-top: 0px; }
blockquote { margin: 1rem 0px; }
li p, li .mathjax-block { margin: 0.5rem 0px; }
li { margin: 0px; position: relative; }
blockquote > :last-child { margin-bottom: 0px; }
blockquote > :first-child { margin-top: 0px; }
.footnotes-area { color: rgb(136, 136, 136); margin-top: 0.714rem; padding-bottom: 0.143rem; }
@media print {
  html, body { height: 100%; }
  .typora-export * { -webkit-print-color-adjust: exact; }
  h1, h2, h3, h4, h5, h6 { break-after: avoid-page; orphans: 2; }
  p { orphans: 4; }
  html.blink-to-pdf { font-size: 13px; }
  .typora-export #write { padding-left: 1cm; padding-right: 1cm; }
  .typora-export #write::after { height: 0px; }
  @page { margin: 20mm 0mm; }
}
.footnote-line { margin-top: 0.714em; font-size: 0.7em; }
a img, img a { cursor: pointer; }
pre.md-meta-block { font-size: 0.8rem; min-height: 2.86rem; white-space: pre-wrap; background: rgb(204, 204, 204); display: block; overflow-x: hidden; }
p .md-image:only-child { display: inline-block; width: 100%; text-align: center; }
#write .MathJax_Display { margin: 0.8em 0px 0px; }
.mathjax-block { white-space: pre; overflow: hidden; width: 100%; }
p + .mathjax-block { margin-top: -1.143rem; }
.mathjax-block:not(:empty)::after { display: none; }
[contenteditable="true"]:active, [contenteditable="true"]:focus { outline: none; box-shadow: none; }
.task-list { list-style-type: none; }
.task-list-item { position: relative; padding-left: 1em; }
.task-list-item input { position: absolute; top: 0px; left: 0px; }
.math { font-size: 1rem; }
.md-toc { min-height: 3.58rem; position: relative; font-size: 0.9rem; border-radius: 10px; }
.md-toc-content { position: relative; margin-left: 0px; }
.md-toc::after, .md-toc-content::after { display: none; }
.md-toc-item { display: block; color: rgb(65, 131, 196); text-decoration: none; }
.md-toc-inner:hover { }
.md-toc-inner { display: inline-block; cursor: pointer; }
.md-toc-h1 .md-toc-inner { margin-left: 0px; font-weight: bold; }
.md-toc-h2 .md-toc-inner { margin-left: 2em; }
.md-toc-h3 .md-toc-inner { margin-left: 4em; }
.md-toc-h4 .md-toc-inner { margin-left: 6em; }
.md-toc-h5 .md-toc-inner { margin-left: 8em; }
.md-toc-h6 .md-toc-inner { margin-left: 10em; }
@media screen and (max-width: 48em) {
  .md-toc-h3 .md-toc-inner { margin-left: 3.5em; }
  .md-toc-h4 .md-toc-inner { margin-left: 5em; }
  .md-toc-h5 .md-toc-inner { margin-left: 6.5em; }
  .md-toc-h6 .md-toc-inner { margin-left: 8em; }
}
a.md-toc-inner { font-size: inherit; font-style: inherit; font-weight: inherit; line-height: inherit; }
.footnote-line a:not(.reversefootnote) { color: inherit; }
.md-attr { display: none; }
.md-fn-count::after { content: "."; }
.md-tag { opacity: 0.5; }
.md-comment { color: rgb(162, 127, 3); opacity: 0.8; font-family: monospace; }
code { text-align: left; }
h1 .md-tag, h2 .md-tag, h3 .md-tag, h4 .md-tag, h5 .md-tag, h6 .md-tag { font-weight: initial; opacity: 0.35; }
a.md-print-anchor { border-width: initial !important; border-style: none !important; border-color: initial !important; display: inline-block !important; position: absolute !important; width: 1px !important; right: 0px !important; outline: none !important; background: transparent !important; text-decoration: initial !important; text-shadow: initial !important; }
.md-inline-math .MathJax_SVG .noError { display: none !important; }
.mathjax-block .MathJax_SVG_Display { text-align: center; margin: 1em 0em; position: relative; text-indent: 0px; max-width: none; max-height: none; min-height: 0px; min-width: 100%; width: auto; display: block !important; }
.MathJax_SVG_Display, .md-inline-math .MathJax_SVG_Display { width: auto; margin: inherit; display: inline-block !important; }
.MathJax_SVG .MJX-monospace { font-family: monospace; }
.MathJax_SVG .MJX-sans-serif { font-family: sans-serif; }
.MathJax_SVG { display: inline; font-style: normal; font-weight: normal; line-height: normal; zoom: 90%; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; }
.MathJax_SVG * { transition: none; }


@font-face { font-family: "Open Sans"; font-style: normal; font-weight: normal; src: local("Open Sans Regular"), url("./github/400.woff") format("woff"); }
@font-face { font-family: "Open Sans"; font-style: italic; font-weight: normal; src: local("Open Sans Italic"), url("./github/400i.woff") format("woff"); }
@font-face { font-family: "Open Sans"; font-style: normal; font-weight: bold; src: local("Open Sans Bold"), url("./github/700.woff") format("woff"); }
@font-face { font-family: "Open Sans"; font-style: italic; font-weight: bold; src: local("Open Sans Bold Italic"), url("./github/700i.woff") format("woff"); }
html { font-size: 16px; }
body { font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; color: rgb(51, 51, 51); line-height: 1.6; }
#write { max-width: 860px; margin: 0px auto; padding: 20px 30px 100px; }
#write > ul:first-child, #write > ol:first-child { margin-top: 30px; }
body > :first-child { margin-top: 0px !important; }
body > :last-child { margin-bottom: 0px !important; }
a { color: rgb(65, 131, 196); }
h1, h2, h3, h4, h5, h6 { position: relative; margin-top: 1rem; margin-bottom: 1rem; font-weight: bold; line-height: 1.4; cursor: text; }
h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, h5:hover a.anchor, h6:hover a.anchor { text-decoration: none; }
h1 tt, h1 code { font-size: inherit; }
h2 tt, h2 code { font-size: inherit; }
h3 tt, h3 code { font-size: inherit; }
h4 tt, h4 code { font-size: inherit; }
h5 tt, h5 code { font-size: inherit; }
h6 tt, h6 code { font-size: inherit; }
h1 { padding-bottom: 0.3em; font-size: 2.25em; line-height: 1.2; border-bottom: 1px solid rgb(238, 238, 238); }
h2 { padding-bottom: 0.3em; font-size: 1.75em; line-height: 1.225; border-bottom: 1px solid rgb(238, 238, 238); }
h3 { font-size: 1.5em; line-height: 1.43; }
h4 { font-size: 1.25em; }
h5 { font-size: 1em; }
h6 { font-size: 1em; color: rgb(119, 119, 119); }
p, blockquote, ul, ol, dl, table { margin: 0.8em 0px; }
li > ol, li > ul { margin: 0px; }
hr { height: 4px; padding: 0px; margin: 16px 0px; background-color: rgb(231, 231, 231); border-width: 0px 0px 1px; border-style: none none solid; border-top-color: initial; border-right-color: initial; border-left-color: initial; border-image: initial; overflow: hidden; box-sizing: content-box; border-bottom-color: rgb(221, 221, 221); }
body > h2:first-child { margin-top: 0px; padding-top: 0px; }
body > h1:first-child { margin-top: 0px; padding-top: 0px; }
body > h1:first-child + h2 { margin-top: 0px; padding-top: 0px; }
body > h3:first-child, body > h4:first-child, body > h5:first-child, body > h6:first-child { margin-top: 0px; padding-top: 0px; }
a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 { margin-top: 0px; padding-top: 0px; }
h1 p, h2 p, h3 p, h4 p, h5 p, h6 p { margin-top: 0px; }
li p.first { display: inline-block; }
ul, ol { padding-left: 30px; }
ul:first-child, ol:first-child { margin-top: 0px; }
ul:last-child, ol:last-child { margin-bottom: 0px; }
blockquote { border-left: 4px solid rgb(221, 221, 221); padding: 0px 15px; color: rgb(119, 119, 119); }
blockquote blockquote { padding-right: 0px; }
table { padding: 0px; word-break: initial; }
table tr { border-top: 1px solid rgb(204, 204, 204); background-color: white; margin: 0px; padding: 0px; }
table tr:nth-child(2n) { background-color: rgb(248, 248, 248); }
table tr th { font-weight: bold; border: 1px solid rgb(204, 204, 204); text-align: left; margin: 0px; padding: 6px 13px; }
table tr td { border: 1px solid rgb(204, 204, 204); text-align: left; margin: 0px; padding: 6px 13px; }
table tr th:first-child, table tr td:first-child { margin-top: 0px; }
table tr th:last-child, table tr td:last-child { margin-bottom: 0px; }
.CodeMirror-gutters { border-right: 1px solid rgb(221, 221, 221); }
.md-fences, code, tt { border: 1px solid rgb(221, 221, 221); background-color: rgb(248, 248, 248); border-radius: 3px; font-family: Consolas, "Liberation Mono", Courier, monospace; padding: 2px 4px 0px; font-size: 0.9em; }
.md-fences { margin-bottom: 15px; margin-top: 15px; padding: 8px 1em 6px; }
.task-list { padding-left: 0px; }
.task-list-item { padding-left: 32px; }
.task-list-item input { top: 3px; left: 8px; }
@media screen and (min-width: 914px) {
}
@media print {
  html { font-size: 13px; }
  table, pre { break-inside: avoid; }
  pre { word-wrap: break-word; }
}
.md-fences { background-color: rgb(248, 248, 248); }
#write pre.md-meta-block { padding: 1rem; font-size: 85%; line-height: 1.45; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; color: rgb(119, 119, 119); margin-top: 0px !important; }
.mathjax-block > .code-tooltip { bottom: 0.375rem; }
#write > h3.md-focus::before { left: -1.5625rem; top: 0.375rem; }
#write > h4.md-focus::before { left: -1.5625rem; top: 0.285714rem; }
#write > h5.md-focus::before { left: -1.5625rem; top: 0.285714rem; }
#write > h6.md-focus::before { left: -1.5625rem; top: 0.285714rem; }
.md-image > .md-meta { border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-family: Consolas, "Liberation Mono", Courier, monospace; padding: 2px 4px 0px; font-size: 0.9em; color: inherit; }
.md-tag { color: inherit; }
.md-toc { margin-top: 20px; padding-bottom: 20px; }
#typora-quick-open { border: 1px solid rgb(221, 221, 221); background-color: rgb(248, 248, 248); }
#typora-quick-open-item { background-color: rgb(250, 250, 250); border-color: rgb(254, 254, 254) rgb(229, 229, 229) rgb(229, 229, 229) rgb(238, 238, 238); border-style: solid; border-width: 1px; }
#md-notification::before { top: 10px; }
.on-focus-mode blockquote { border-left-color: rgba(85, 85, 85, 0.117647); }
header, .context-menu, .megamenu-content, footer { font-family: "Segoe UI", Arial, sans-serif; }






</style>
</head>
<body class='typora-export' >
<div  id='write'  class = 'is-node'><h1><a name='header-n0' class='md-header-anchor '></a>Git实战</h1><div class='md-toc' mdtype='toc'><p class="md-toc-content"><span class="md-toc-item md-toc-h1" data-ref="n0"><a class="md-toc-inner" href="#header-n0">Git实战</a></span><span class="md-toc-item md-toc-h2" data-ref="n5"><a class="md-toc-inner" href="#header-n5">一章 快速使用</a></span><span class="md-toc-item md-toc-h3" data-ref="n8"><a class="md-toc-inner" href="#header-n8">1.1 git是什么</a></span><span class="md-toc-item md-toc-h3" data-ref="n13"><a class="md-toc-inner" href="#header-n13">1.2 安装</a></span><span class="md-toc-item md-toc-h3" data-ref="n25"><a class="md-toc-inner" href="#header-n25">1.3 报家门</a></span><span class="md-toc-item md-toc-h3" data-ref="n31"><a class="md-toc-inner" href="#header-n31">1.4 代码管理</a></span><span class="md-toc-item md-toc-h5" data-ref="n32"><a class="md-toc-inner" href="#header-n32">1.4.1 创建版本库</a></span><span class="md-toc-item md-toc-h4" data-ref="n38"><a class="md-toc-inner" href="#header-n38">1.4.2 添加文件</a></span><span class="md-toc-item md-toc-h4" data-ref="n52"><a class="md-toc-inner" href="#header-n52">1.4.3 修改文件</a></span><span class="md-toc-item md-toc-h4" data-ref="n61"><a class="md-toc-inner" href="#header-n61">1.4.4 删除文件</a></span><span class="md-toc-item md-toc-h3" data-ref="n66"><a class="md-toc-inner" href="#header-n66">1.5 远程仓库</a></span><span class="md-toc-item md-toc-h4" data-ref="n71"><a class="md-toc-inner" href="#header-n71">1.5.1 注册git在线仓库的账号</a></span><span class="md-toc-item md-toc-h4" data-ref="n78"><a class="md-toc-inner" href="#header-n78">1.5.2 创建项目</a></span><span class="md-toc-item md-toc-h4" data-ref="n88"><a class="md-toc-inner" href="#header-n88">1.5.3 把代码推到远程仓库</a></span><span class="md-toc-item md-toc-h4" data-ref="n98"><a class="md-toc-inner" href="#header-n98">1.5.4 团队合作</a></span><span class="md-toc-item md-toc-h2" data-ref="n118"><a class="md-toc-inner" href="#header-n118">二章 git的特点</a></span><span class="md-toc-item md-toc-h4" data-ref="n119"><a class="md-toc-inner" href="#header-n119">2.1 分布式版本控制器</a></span><span class="md-toc-item md-toc-h2" data-ref="n142"><a class="md-toc-inner" href="#header-n142">三章 代码管理</a></span><span class="md-toc-item md-toc-h3" data-ref="n143"><a class="md-toc-inner" href="#header-n143">3.1 工作区和版本库</a></span><span class="md-toc-item md-toc-h3" data-ref="n176"><a class="md-toc-inner" href="#header-n176">3.2 文件操作</a></span><span class="md-toc-item md-toc-h3" data-ref="n186"><a class="md-toc-inner" href="#header-n186">3.3 改动日志</a></span><span class="md-toc-item md-toc-h3" data-ref="n199"><a class="md-toc-inner" href="#header-n199">3.4 版本切换</a></span><span class="md-toc-item md-toc-h2" data-ref="n223"><a class="md-toc-inner" href="#header-n223">四章 分支管理</a></span><span class="md-toc-item md-toc-h3" data-ref="n224"><a class="md-toc-inner" href="#header-n224">4.1 分支有什么用?</a></span><span class="md-toc-item md-toc-h3" data-ref="n249"><a class="md-toc-inner" href="#header-n249">4.2 查看分支</a></span><span class="md-toc-item md-toc-h3" data-ref="n254"><a class="md-toc-inner" href="#header-n254">4.3 创建分支</a></span><span class="md-toc-item md-toc-h3" data-ref="n258"><a class="md-toc-inner" href="#header-n258">4.4 切换分支</a></span><span class="md-toc-item md-toc-h3" data-ref="n263"><a class="md-toc-inner" href="#header-n263">4.5 合并分支</a></span><span class="md-toc-item md-toc-h3" data-ref="n274"><a class="md-toc-inner" href="#header-n274">4.6 删除分支</a></span><span class="md-toc-item md-toc-h3" data-ref="n276"><a class="md-toc-inner" href="#header-n276">4.7 快速创建和切换分支</a></span><span class="md-toc-item md-toc-h2" data-ref="n280"><a class="md-toc-inner" href="#header-n280">五章 远程仓库</a></span><span class="md-toc-item md-toc-h3" data-ref="n290"><a class="md-toc-inner" href="#header-n290">5.1 添加远程库</a></span><span class="md-toc-item md-toc-h3" data-ref="n292"><a class="md-toc-inner" href="#header-n292">5.2 修改远程库名称</a></span><span class="md-toc-item md-toc-h2" data-ref="n325"><a class="md-toc-inner" href="#header-n325">引用文献</a></span></p></div><p></p><h2><a name='header-n5' class='md-header-anchor '></a>一章 快速使用</h2><h3><a name='header-n8' class='md-header-anchor '></a>1.1 git是什么</h3><p>git是一种版本控制器.</p><p>更直白说,团队开发时,管理代码用的软件.</p><h3><a name='header-n13' class='md-header-anchor '></a>1.2 安装</h3><p>git在Linux,Mac,Win下都可以安装.</p><p>本文是以Win7系统为环境编写的.</p><p>Window环境:</p><p>到 <a href='https://git-for-windows.github.io/'>https://git-for-windows.github.io/ </a>下载软件, 双击,一路&quot;Next&quot;,安装完毕.到开始菜单找&quot;git bash&quot;,如下图</p><p> Linux环境安装git,centos,redhat系统</p><pre class="md-fences md-end-block" lang="shell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure">AخA</div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment"># yum install git</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 23px;"></div></div></div></pre><h3><a name='header-n25' class='md-header-anchor '></a>1.3 报家门</h3><p>人在江湖,岂能没有名号.</p><p>在你用git之前,要先报家门,否则代码不能提交.</p><pre class="md-fences md-end-block" lang="shell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><span><span>​</span>x</span></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-def">$ git</span> config <span class="cm-attribute">--global</span> user.name<span class="cm-comment">#你是谁</span></span></pre></div><pre class=""><span style="padding-right: 0.1px;"><span>​</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-def">$ git</span> config <span class="cm-attribute">--globaluser</span>.email <span class="cm-comment">#怎么联系你</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 68px;"></div></div></div></pre><h3><a name='header-n31' class='md-header-anchor '></a>1.4 代码管理</h3><h5><a name='header-n32' class='md-header-anchor '></a>1.4.1 创建版本库</h5><pre class='md-fences mock-cm' style='display:block;position:relative'>$D:\xampp\htdocs\git

$ git init</pre><p>注意:
  不要把仓库建在中文目录下,可能出问题.
  .git 是个隐藏目录,不要乱碰.(你的每一次代码修改它都帮你记录着呢)</p><h4><a name='header-n38' class='md-header-anchor '></a>1.4.2 添加文件</h4><p>在git目录下,用你喜欢的编辑器(sublime/vim等),
开发你的程序. 比如,index.php
echo &#39;hello git&#39;;
编辑PHP文件后, # git status , 查看仓库状态
实例如下:</p><p>$ git status</p><p>可见,此时git发现有一个新文件,但并没有把此文件纳入管理.</p><p>我们需要两步,让git仓库管理index.php</p><pre class='md-fences mock-cm' style='display:block;position:relative'>git add index.php

把index.php 提交到暂存区

git commit -m &quot;新建index.php&quot;

把index.php 提交到版本库</pre><h4><a name='header-n52' class='md-header-anchor '></a>1.4.3 修改文件</h4><p>如果修改了文件,也不要忘记提交到版本库这个过程和添加文件是一样的
一样是需要两步,让git仓库记录此次改变</p><pre class='md-fences mock-cm' style='display:block;position:relative'>git add index.php
把index.php 提交到暂存区
git commit -m &quot;改了第2行&quot;
把index.php 提交到版本库</pre><p>实例:
$ git add index.php
$ git commit -m &quot;改了第2行&quot;</p><h4><a name='header-n61' class='md-header-anchor '></a>1.4.4 删除文件</h4><p>用rm命令删除文件,并直接commit,提交到版本库例:先创建一个foo.php,供练习删除用
实例如下:</p><pre class='md-fences mock-cm' style='display:block;position:relative'>$ touch foo.php  创建foo.php
$ git add foo.php
$ git commit -m &quot;删除&quot; 
</pre><h3><a name='header-n66' class='md-header-anchor '></a>1.5 远程仓库</h3><p>经过前面的练习,你在本地的仓库里管理代码已经比较熟练了.但如果是团队开发,如何配合起来呢?
我们可以把版本仓库放在互联网上.
开发者把自己最新的版本推到线上仓库,同时,把线上仓库的最新代码,拉到自己本地.这样,就可以配合工作了.</p><h4><a name='header-n71' class='md-header-anchor '></a>1.5.1 注册git在线仓库的账号</h4><p>国外: <a href='http://www.github.com' target='_blank' >http://www.github.com</a>
国内: <a href='http://git.oschina.net' target='_blank' >http://git.oschina.net</a>
github.com也是目前程序员的装逼利器,在github上挂个项目,逼格瞬间提升两三档.不过由于是国外网站,速度不咋样.
出于学习的方便,我在oschina.net给大家演示.
请立即打开 <a href='http://git.oschina.net' target='_blank' >http://git.oschina.net</a> 注册一个账户.</p><h4><a name='header-n78' class='md-header-anchor '></a>1.5.2 创建项目</h4><p>在oschina注册后,&quot;新建项目&quot;,我们先建一个测试项目,叫git.如下:</p><p><img src='D:/LenovoCloud1/%E5%85%84%E5%BC%9F%E8%BF%9E%E6%95%99%E7%A0%94%E7%BB%84/laravel/%E9%A1%B9%E7%9B%AE%E8%AF%BE%E4%BB%B6/git1.png' alt='git1' /></p><p>oschina为此项目提供的仓库地址有2个.
http地址:<a href='https://git.oschina.net/kent_/test.git' target='_blank' >https://git.oschina.net/kent_/test.git</a>
ssh地址: git@git.oschina.net:kent_/test.git
近几章的学习,我们先用http地址.</p><h4><a name='header-n88' class='md-header-anchor '></a>1.5.3 把代码推到远程仓库</h4><p>推: push
为本地库添加远程库
$ git remote add origin <a href='https://git.oschina.net/kent/test.git' target='_blank' >https://git.oschina.net/kent/test.git</a>
意思是:添加1个远程库,代号是origin,地址是 <a href='https://....test.git' target='_blank' >https://....test.git</a>
push 推代码
push origin master
意思是,把本地的版本(默认是master),推到代号为origin的远程库去.
这个过程会让你输入用户名/密码,即你注册时的账户密码</p><h4><a name='header-n98' class='md-header-anchor '></a>1.5.4 团队合作</h4><p>你想让一位叫&quot;kent0106&quot;和程序员,和你一起开发.
首先kent_账户把kent0106添加到此项目中来,让其成为开发者
项目-&gt;管理-&gt;项目成员管理-&gt;开发者-&gt;添加项目成员-&gt;输入&quot;kent0106&quot;</p><p><img src='D:/LenovoCloud1/%E5%85%84%E5%BC%9F%E8%BF%9E%E6%95%99%E7%A0%94%E7%BB%84/laravel/%E9%A1%B9%E7%9B%AE%E8%AF%BE%E4%BB%B6/git2.png' alt='git2' /></p><p>他应该先把远程库复制一份到他本地.
命令: clone</p><pre class='md-fences mock-cm' style='display:block;position:relative'>$ cd git2
$ git http://git.oschina.net/kent_/test/team/test.git
$ ls
index.php
</pre><p>&quot;kent0106&quot;修改并push他的代码.
另一个账户,如何得到仓库里的最新代码?
推:push; 拉? pull!
对的. 你已经猜到了,用pull命令.
kent_账户拉取最新代码
此时,查看最新的index.php内容,第4行,多了&quot;kent0106&quot;的那一行.
至此,你可以和小伙伴愉快的用git配合开发了.
如果要掌握更多git功能,后面还有四章, 敬请期待!</p><h2><a name='header-n118' class='md-header-anchor '></a>二章 git的特点</h2><h4><a name='header-n119' class='md-header-anchor '></a>2.1 分布式版本控制器</h4><p>何为分布式? 与集中式相比有何特点?
以SVN为例:</p><p><img src='D:/LenovoCloud1/%E5%85%84%E5%BC%9F%E8%BF%9E%E6%95%99%E7%A0%94%E7%BB%84/laravel/%E9%A1%B9%E7%9B%AE%E8%AF%BE%E4%BB%B6/svn.png' alt='svn' /></p><p>中心的svn服务器中,存储着代码版本的变迁,及日志.
你想查看改动日志,请联网SVN服务器.
你想退回上个版本,请联网SVN服务器.
你想创建新的分支,请联网SVN服务器.
联网不说,万一SVN服务器要是坏了???后果你说呢.
而git是这样的:</p><p><img src='D:/LenovoCloud1/%E5%85%84%E5%BC%9F%E8%BF%9E%E6%95%99%E7%A0%94%E7%BB%84/laravel/%E9%A1%B9%E7%9B%AE%E8%AF%BE%E4%BB%B6/git3.png' alt='git3' /></p><p>每个开发者的电脑上,都有完整的版本,日志,及分支信息.
但开发者不依赖于服务器,可以查看日志,回退版本,创建分支.
当然,世界各地的开发需要交换最新的版本信息,
因此,git往往也需要服务器.
但是,本质的区别在于:
git服务器是供开发者&quot;交换&quot;代码,服务器数据丢了没关系,分分钟再建一台.
svn的服务器,不仅交换代码,还控制着日志,版本,分支.服务器数据丢了就完了.</p><h2><a name='header-n142' class='md-header-anchor '></a>三章 代码管理</h2><h3><a name='header-n143' class='md-header-anchor '></a>3.1 工作区和版本库</h3><p>如果你想更清晰的学习git,你必须要了解3个重要区域.
工作区, 即开发者的工作目录.
暂存区, 修改已被记录,但尚未录入版本库的区域.
版本库, 存储变化日志及版本信息.</p><p><img src='D:/LenovoCloud1/%E5%85%84%E5%BC%9F%E8%BF%9E%E6%95%99%E7%A0%94%E7%BB%84/laravel/%E9%A1%B9%E7%9B%AE%E8%AF%BE%E4%BB%B6/git4.png' alt='git4' /></p><p>做个实验: 创建并提交一个文件的全过程
touch hello.txt 创建文件
$ git status 查看状态,如下:</p><pre class='md-fences mock-cm' style='display:block;position:relative'>$ git status
On branch master
Untracked files:
  (use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)

        hello.txt

nothing added to commit but untracked files present (use &quot;git add&quot; to track)
</pre><blockquote><p>意思是说:有未被跟踪的文件 readme.txt.
(文件在你的工作区,还没告诉git去管理它,当然没被跟踪了.)
你可以用git add <file> ,把它加入待提交列表</p></blockquote><p>git add hello.txt 添加到暂存区
再次查看状态,如下:</p><pre class='md-fences mock-cm' style='display:block;position:relative'>$ git status
On branch master
Changes to be committed:
  (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)

        new file:   hello.txt</pre><blockquote><p>代码的变化,可以提交(commit)了</p><p>也可以git reset HEAD &lt;file把它从暂存区拿出来.</p></blockquote><pre class='md-fences mock-cm' style='display:block;position:relative'>git commit &lt;file&gt; -m &lt;注释&gt; 提交代码

$ git commit hello.txt -m &quot;add hello.txt&quot;
</pre><p>再次查看状态,如下:</p><pre class='md-fences mock-cm' style='display:block;position:relative'>$ git status
On branch master
nothing to commit, working tree clean</pre><p>可以看到,所有的变动,已录入版本库. 目前工作区没有新内容,是干净的.</p><h3><a name='header-n176' class='md-header-anchor '></a>3.2 文件操作</h3><p>添加多个文件
git add <file1> <file2> #添加file1,file2
git add *.txt #添加当前目录下的.txt文档
git add . #添加当前目录的所有变化
删除文件
git rm <file>
移动或改名
git mv 源文件 新文件</p><h3><a name='header-n186' class='md-header-anchor '></a>3.3 改动日志</h3><p>每个文件/目录发生的版本变化,我们都可以追溯.
命令为:&quot;git log &quot;
常用格式:
git log 查看项目的日志
git log <file> 查看某文件的日志
git log . 查看本目录的日志
例:
git log 显示如下:</p><pre class='md-fences mock-cm' style='display:block;position:relative'>$ git log
commit cbcc32129bb4076bdc8b66dc95ce0feb15ce8eef
Author: 紫气东来_ &lt;281008102@qq.com&gt;
Date:   Mon Jun 19 20:31:43 2017 +0800

    add hello.txt
commit 6b18a337eca32661df95c2d2c0bd91aab28ca40c
Author: 紫气东来_ &lt;281008102@qq.com&gt;
Date:   Mon Jun 19 20:23:17 2017 +0800
    update</pre><p>如果感觉log有点乱,可以git log --pretty=oneline ,让日志单行显示.</p><h3><a name='header-n199' class='md-header-anchor '></a>3.4 版本切换</h3><p>我们针对ver.txt,连续修改4次,形成4个版本,练习版本切换.</p><pre class='md-fences mock-cm' style='display:block;position:relative'>one line
second line
third line
four line</pre><p>git reflog 查看版本变化</p><pre class='md-fences mock-cm' style='display:block;position:relative'>$ git reflog
5d5df85 HEAD@{0}: commit: four
6207e59 HEAD@{1}: commit: three
70110b9 HEAD@{2}: commit: two
bc65223 HEAD@{3}: commit (initial): one</pre><p>HEAD指向当前版本5d5df86 ,
切换为head的前1版本,git reset --hard HEAD^
切换为head的前2版本,git reset --hard HEAD^^
切换为head的前100版本,git reset --hard HEAD~100
实例:</p><p>$ git reset --hard HEAD^^
HEAD is now at 70110b9 two
此时,查看ver.txt的内容变为:</p><pre class='md-fences mock-cm' style='display:block;position:relative'>one line
two line</pre><p>也可以利用版本号来切换,例</p><pre class='md-fences mock-cm' style='display:block;position:relative'>$ git reset --hard 6207e59
HEAD is now at 6207e59 three</pre><p>注意:版本号不用写那么长,能要能保证不与其他版本号重复就行.
例git reset --hard 6207</p><h2><a name='header-n223' class='md-header-anchor '></a>四章 分支管理</h2><h3><a name='header-n224' class='md-header-anchor '></a>4.1 分支有什么用?</h3><p>在开发中,遇到这样的情况怎么办?
网站已有支付宝在线支付功能,要添加&quot;微信支付&quot;.
修改了3个文件, wechat.php ,pay.php
刚做到一半,突然有个紧急bug: 支付宝支付后不能修改订单状态.
你需要立即马上修改这个bug,需要修改的文件是,ali.php ,pay.php .
问题是:pay.php ,已经被你修改过,而且尚未完成.
直接在此基础上改,肯定有问题.
把pay.php倒回去? 那我之前的工作白费了.
此时你肯定会想: 在做&quot;微信支付&quot;时,能否把仓库复制一份,在此副本上修改,不影响原仓库的内容.修改完毕后,再把副本上的修改合并过去.
好的,这时你已经有了分支的思想.
前面见过的master ,即是代码的主干分支,
事实上,在实际的开发中,往往不会直接修改和提交到master分支上.
而是创建一个dev分支,在dev分支上,修改测试,没问题了,再把dev分支合并到master上.
如果有了分支,刚才的难题就好解决了,如下图:</p><p><img src='D:/LenovoCloud1/%E5%85%84%E5%BC%9F%E8%BF%9E%E6%95%99%E7%A0%94%E7%BB%84/laravel/%E9%A1%B9%E7%9B%AE%E8%AF%BE%E4%BB%B6/git5.png' alt='git5' /></p><p>在做&quot;微信支付&quot;时,我们创建一个wechat分支.
把wechat分支commit ,此时,master分支内容不会变,因为分支不同.
当遇到紧急bug时,创建一个AliBug分支.
修复bug后,把AliBug分支合并到master分支上.
再次从容切换到wechat分支上,接着开发&quot;微信支付&quot;功能,开发完毕后,
把wechat分支合并到master分支上.</p><h3><a name='header-n249' class='md-header-anchor '></a>4.2 查看分支</h3><p>查看所有分支 git branch
例</p><pre class="md-fences md-end-block" lang="git branch"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;">master # 说明只有master分支,且处于master分支.</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 23px;"></div></div></div></pre><h3><a name='header-n254' class='md-header-anchor '></a>4.3 创建分支</h3><p>创建dev分支 git branch dev</p><pre class="md-fences md-end-block" lang="git branch dev # 创建dev分支"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;">git branch #查看分支</span></pre></div><pre class=""><span style="padding-right: 0.1px;">dev</span></pre><pre class=""><span style="padding-right: 0.1px;">master # dev分支创建成功,但仍处于master分支</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 68px;"></div></div></div></pre><h3><a name='header-n258' class='md-header-anchor '></a>4.4 切换分支</h3><p>切换到dev分支 git checkout dev
再次查看</p><pre class='md-fences mock-cm' style='display:block;position:relative'>$ git branch
 dev
master # 已切换到dev分支上</pre><h3><a name='header-n263' class='md-header-anchor '></a>4.5 合并分支</h3><p>当我们在dev上开发某功能,并测试通过后,可以把dev的内容合并到master分支.
例:
当前的hello.txt 内容为&quot;so so&quot;,在dev分支下,添加一行&quot;from dev&quot;
并提交</p><pre class='md-fences mock-cm' style='display:block;position:relative'>git add hello.txt
git commit -m &quot;mod in dev&quot;</pre><p>再次切换到master ,查看readme.txt的内容,仍为&#39;so so&#39;
合并dev分支,git merge dev , 如下:</p><pre class='md-fences mock-cm' style='display:block;position:relative'>$ git merge dev
Updating c5364fe..412926b
Fast-forward
hello.txt | 1 +
1 file changed, 1 insertion(+)
再次查看hello.txt的内容,已变为&quot;soso from dev&quot;;</pre><h3><a name='header-n274' class='md-header-anchor '></a>4.6 删除分支</h3><pre class='md-fences mock-cm' style='display:block;position:relative'>git branch -d dev
Deleted branch dev (was 412926b).</pre><h3><a name='header-n276' class='md-header-anchor '></a>4.7 快速创建和切换分支</h3><p>git checkout -b dev # 创建dev分支并立即切换到dev分支
即起到git branch dev和git checkout dev的共同作用.</p><h2><a name='header-n280' class='md-header-anchor '></a>五章 远程仓库</h2><p>查看远程仓库
查看远程仓库:git remote
查看仓库地址:git remote -v
例:</p><pre class='md-fences mock-cm' style='display:block;position:relative'>git remote -v
origin https://git.oschina.net/kent_/test.git (fetch)
origin https://git.oschina.net/kent_/test.git (push)</pre><p>删除远程库</p><pre class='md-fences mock-cm' style='display:block;position:relative'>命令:git remote remove &lt;远程库名&gt;
示例:git remote remove origin</pre><h3><a name='header-n290' class='md-header-anchor '></a>5.1 添加远程库</h3><p>命令:git remote add &lt;远程库名&gt; &lt;远程库地址&gt;
示例:
git remote add origin <a href='https://git.oschina.net/kent/test.git' target='_blank' >https://git.oschina.net/kent/test.git</a>
注: 远程库名一般叫origin ,但并非强制,你可以自己起名.
例:
git remote add online <a href='https://git.oschina.net/kent/test.git' target='_blank' >https://git.oschina.net/kent/test.git</a></p><h3><a name='header-n292' class='md-header-anchor '></a>5.2 修改远程库名称</h3><pre class='md-fences mock-cm' style='display:block;position:relative'>git remote rename &lt;旧名称&gt; &lt;新名称&gt;
例:
git remote rename online oschina</pre><p>公钥登陆
我们push本地仓库到远程时,总要输入用户名/密码,这很不方便.
配置公钥,可以避免频繁输用户名/密码的麻烦.</p><ol start='' ><li><p>配置ssh格式的远程仓库地址
git remote add 远程仓库名 远程仓库地址
例:
git remote add gitaddr git@git.oschina.net:kent/test.git</p></li><li><p>创建ssh key
ssh-keygen -t rsa -C &quot;<a href='mailto:youremail@example.com' target='_blank' >youremail@example.com</a>&quot; ,把邮件地址换成你自己的邮件地址,一直回车,不用输入密码.完成后,可以在用户主目录里找
到.ssh目录,内有id_rsa和id_rsa.pub两个文件. id_rsa是私钥,id_rsa.pub是公钥.
这两把钥匙是成对的,可以让分别持有私钥和公钥的双方相互认识.</p></li><li><p>把公钥放在服务器
用记事本打开id_rsa.pub ,复制公钥内容.
登陆git.oschina.net,如下图,填入公钥并保存.</p><p><img src='D:/LenovoCloud1/%E5%85%84%E5%BC%9F%E8%BF%9E%E6%95%99%E7%A0%94%E7%BB%84/laravel/%E9%A1%B9%E7%9B%AE%E8%AF%BE%E4%BB%B6/git6.png' alt='git6' /></p></li><li><p>push本地仓库到远程,发现不用填密码了
git push gitaddr master</p></li></ol><h2><a name='header-n325' class='md-header-anchor '></a>引用文献</h2><p><a href='https://en.wikipedia.org/wiki/Concurrent_Versions_System' target='_blank' >https://en.wikipedia.org/wiki/Concurrent_Versions_System</a>
<a href='http://www.linux.com/news/featured-blogs/185-jennifer-cloer/821541-10-years-of-git-an-interview-with-git-creator-linus-torvalds' target='_blank' >http://www.linux.com/news/featured-blogs/185-jennifer-cloer/821541-10-years-of-git-an-interview-with-git-creator-linus-torvalds</a>
<a href='http://git-scm.com/book/zh/v2' target='_blank' >http://git-scm.com/book/zh/v2</a></p></div>
</body>
</html>